use "C:\Users\karti\Documents\Data\regressions\paper_2\data_corrected_for_regs_DDD_with nssdist.dta", clear

tab yr_qtr, gen(yr_qtr_id)



*tab year, gen(yr_id)

tab new_state_dist_code, gen(nssdist)
gen t2 =  time - 1
forvalues j = 1/150 {
*linear
gen nssdist_`j'=nssdist`j'*t2
}

drop interact* r post_dif w fci_tot triple_1_r triple_1_fci triple_1_w dum_w dum_fci dum2_1_fci dum2_1_w dum dum2_1 tr t triple_p triple_p_r triple_p_w fci_year fci_year_r fci_year_w

gen post_dif = (year>=date) 

gen interact1 = 0
replace interact1 = marketing_reform*post_dif


gen interact2 = 0
replace interact2=chand_reform*post_dif

keep if age>16
keep if age<61

gen r = (rice_prop_FCI_produced>0)
gen w = (wheat_prop_FCI_produced>0)

gen fci_tot = (r==1 | w==1)


gen triple_1_fci =interact1*fci_tot



gen dum_fci = fci_tot*post_dif
gen dum2_1 = fci_tot*marketing_reform



gen dum = fci_tot*post_dif

gen triple_2_fci =interact2*fci_tot

gen dum2_2 = fci_tot * chand_reform

global indiv_controls "age hhsize hindu muslim r_others sc st c_others"
global dist_controls "wheat_prod rice_prod no_agri_worker_united agri_worker"

**both
areg log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using both_statedddfeb.xls, replace  ctitle("") keep(triple_1_fci interact1 dum_fci dum2_1) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr $indiv_controls $dist_controls  [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using both_statedddfeb.xls, append  ctitle("") keep(triple_1_fci interact1 dum_fci dum2_1) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr $indiv_controls $dist_controls nssdist_* [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using both_statedddfeb.xls, append  ctitle("") keep(triple_1_fci interact1 dum_fci dum2_1) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

egen dt = group(new_state_dist_code)

cgmwildboot log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr $indiv_controls i.dt nssdist_* [aw=weight] , cluster(dt) bootcluster(dt) [null(0 0) reps(400) seed(1234)]


reg log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr $indiv_controls i.dt nssdist_* [aw=weight], vce(bootstrap, cluster(dt))cluster() 


bootstrap _b, cluster(dt) reps(400) seed(10101): xtmixed

cgmwildboot triple_1_fci , reps (9999) gridpoints (20) 

******************************************************************************************************************
**robustness 1: chand


areg log_real_agwage triple_2_fci interact2 dum_fci dum2_2 fci_tot chand_reform i.yr_qtr $indiv_controls $dist_controls nssdist_* [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)

** does not give consistent results

** robustness 2

egen ste = group(state)

forval x = 1/14{


areg log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr $indiv_controls nssdist_* [aweight=weight] if(ste!=`x'), cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using removing_onestatedddf_02_23.xls, append  ctitle("Excluding" `x') keep(triple_1_fci) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

}


** robustness 3 

set matsize 1234


areg log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr $indiv_controls $dist_controls nssdist_*  [aweight=weight] if(date!=2004), cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using removing_oneyear_02_23.xls, replace  ctitle("Excluding" 2004) keep(triple_1_fci) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr $indiv_controls $dist_controls nssdist_*  [aweight=weight] if(date!=2005), cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using removing_oneyear_02_23.xls, append  ctitle("Excluding" 2005) keep(triple_1_fci) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr $indiv_controls $dist_controls nssdist_*[aweight=weight] if(date!=2006), cluster(new_state_dist_code) absorb(new_state_dist_code) 
outreg2 using removing_oneyear_02_23.xls, append  ctitle("Excluding" 2006) keep(triple_1_fci) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_fci interact1 dum_fci dum2_1 fci_tot marketing_reform i.yr_qtr $indiv_controls $dist_controls nssdist_*[aweight=weight] if(date!=2007), cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using removing_oneyear_02_23.xls, append  ctitle("Excluding" 2007) keep(triple_1_fci) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

************************












































**DDD - rice

areg log_real_agwage triple_1_r interact1 dum dum2_1 r marketing_reform i.yr_qtr [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using rice_statedddfeb.xls, replace  ctitle("") keep(triple_1_r interact1 dum dum2_1) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_r interact1 dum dum2_1 r marketing_reform i.yr_qtr $indiv_controls $dist_controls [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using rice_statedddfeb.xls, append  ctitle("") keep(triple_1_r interact1 dum dum2_1) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_r interact1 dum dum2_1 r marketing_reform i.yr_qtr $indiv_controls $dist_controls nssdist_* [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using rice_statedddfeb.xls, append  ctitle("") keep(triple_1_r interact1 dum dum2_1) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons


** Wheat


areg log_real_agwage triple_1_w interact1 dum_w dum2_1_w w marketing_reform i.yr_qtr [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheat_statedddfeb.xls, replace  ctitle("") keep(triple_1_w interact1 dum_w dum2_1_w) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_w interact1 dum_w dum2_1_w w marketing_reform i.yr_qtr  $indiv_controls $dist_controls [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheat_statedddfeb.xls, append  ctitle("") keep(triple_1_w interact1 dum_w dum2_1_w) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons


areg log_real_agwage triple_1_w interact1 dum_w dum2_1_w w marketing_reform i.yr_qtr $indiv_controls $dist_controls nssdist_* [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheat_statedddfeb.xls, append  ctitle("") keep(triple_1_w interact1 dum_w dum2_1_w) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons




**********************************************************************************
**Wheat only
gen w_only = (w==1 & r==0)

gen triple_1_w_only = interact1*w_only


gen dum_w_only = w_only*post_dif


gen dum2_1_w_only = w_only*marketing_reform

** Wheat only


areg log_real_agwage triple_1_w_only interact1 dum_w_only dum2_1_w_only w_only marketing_reform i.yr_qtr [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheato_statedddfeb.xls, replace  ctitle("") keep(triple_1_w_only interact1 dum_w_only dum2_1_w_only) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_w_only interact1 dum_w_only dum2_1_w_only w_only marketing_reform i.yr_qtr age hhsize hindu muslim r_others sc st c_others [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheato_statedddfeb.xls, append  ctitle("") keep(triple_1_w_only interact1 dum_w_only dum2_1_w_only) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons


areg log_real_agwage triple_1_w_only interact1 dum_w_only dum2_1_w_only w_only marketing_reform i.yr_qtr nsstate_* age hhsize hindu muslim r_others sc st c_others [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheato_statedddfeb.xls, append  ctitle("") keep(triple_1_w_only interact1 dum_w_only dum2_1_w_only) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons
*************************
**Rice only
gen r_only = (w==0 & r==1)

gen triple_1_r_only = interact1*r_only


gen dum_r_only = r_only*post_dif


gen dum2_1_r_only = r_only*marketing_reform


areg log_real_agwage triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only marketing_reform i.yr_qtr [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using riceo_statedddfeb.xls, replace  ctitle("") keep(triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only ) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only marketing_reform i.yr_qtr age hhsize hindu muslim r_others sc st c_others [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using riceo_statedddfeb.xls, append  ctitle("") keep(triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only ) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons


areg log_real_agwage triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only marketing_reform i.yr_qtr nsstate_* age hhsize hindu muslim r_others sc st c_others [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using riceo_statedddfeb.xls, append  ctitle("") keep(triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only ) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons
**************************
** DDD Decomposition
use "C:\Users\karti\Documents\Data\regressions\paper_2\data_corrected_for_regs_DDD_with nssdist.dta", clear

tab yr_qtr, gen(yr_qtr_id)



*tab year, gen(yr_id)

tab new_state_dist_code, gen(nssdist)
gen t2 =  time - 1
forvalues j = 1/150 {
*linear
gen nssdist_`j'=nssdist`j'*t2
}

drop interact* r post_dif w fci_tot triple_1_r triple_1_fci triple_1_w dum_w dum_fci dum2_1_fci dum2_1_w dum dum2_1 tr t triple_p triple_p_r triple_p_w fci_year fci_year_r fci_year_w

gen post_dif = (year>=date) 


gen interact1 = 0
replace interact1 = marketing_reform*post_dif


gen r = (rice_prop_FCI_produced>0)
gen w = (wheat_prop_FCI_produced>0)

gen fci_tot = (r==1 | w==1)

gen triple_1_r = interact1*r
gen triple_1_w = interact1*w
gen triple_1_fci =interact1*fci_tot

gen dum_w = w*post_dif

gen dum_fci = fci_tot*post_dif
gen dum2_1_fci = fci_tot*marketing_reform

gen dum2_1_w = w*marketing_reform
gen dum = r*post_dif
gen dum2_1 = r * marketing_reform





egen tr = group(year)


gen t = tr*marketing_reform

gen triple_p = t*fci_tot

gen triple_p_r = t*r

gen triple_p_w = t*w



gen fci_year = fci_tot * tr
gen fci_year_r = r * tr
gen fci_year_w = w * tr


global indiv_controls "age hhsize hindu muslim r_others sc st c_others"
global dist_controls "wheat_prod rice_prod no_agri_worker_united agri_worker"

areg log_real_agwage triple_1_r interact1 dum dum2_1 r marketing_reform i.yr_qtr [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using rice_statedddfeb.xls, replace  ctitle("") keep(triple_1_r interact1 dum dum2_1) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_r interact1 dum dum2_1 r marketing_reform i.yr_qtr $indiv_controls $dist_controls [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using rice_statedddfeb.xls, append  ctitle("") keep(triple_1_r interact1 dum dum2_1) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_r interact1 dum dum2_1 r marketing_reform i.yr_qtr nssdist_* $indiv_controls $dist_controls [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using rice_statedddfeb.xls, append  ctitle("") keep(triple_1_r interact1 dum dum2_1) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons


** Wheat


areg log_real_agwage triple_1_w interact1 dum_w dum2_1_w w marketing_reform i.yr_qtr [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheat_statedddfeb.xls, replace  ctitle("") keep(triple_1_w interact1 dum_w dum2_1_w) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_w interact1 dum_w dum2_1_w w marketing_reform i.yr_qtr  $indiv_controls $dist_controls [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheat_statedddfeb.xls, append  ctitle("") keep(triple_1_w interact1 dum_w dum2_1_w) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons


areg log_real_agwage triple_1_w interact1 dum_w dum2_1_w w marketing_reform i.yr_qtr nssdist_* $indiv_controls $dist_controls[aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheat_statedddfeb.xls, append  ctitle("") keep(triple_1_w interact1 dum_w dum2_1_w) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons



**Wheat only
gen w_only = (w==1 & r==0)

gen triple_1_w_only = interact1*w_only


gen dum_w_only = w_only*post_dif


gen dum2_1_w_only = w_only*marketing_reform

** Wheat only


areg log_real_agwage triple_1_w_only interact1 dum_w_only dum2_1_w_only w_only marketing_reform i.yr_qtr [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheato_statedddfeb.xls, replace  ctitle("") keep(triple_1_w_only interact1 dum_w_only dum2_1_w_only) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_w_only interact1 dum_w_only dum2_1_w_only w_only marketing_reform i.yr_qtr $indiv_controls $dist_controls [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheato_statedddfeb.xls, append  ctitle("") keep(triple_1_w_only interact1 dum_w_only dum2_1_w_only) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons


areg log_real_agwage triple_1_w_only interact1 dum_w_only dum2_1_w_only w_only marketing_reform i.yr_qtr nssdist_* $indiv_controls $dist_controls [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheato_statedddfeb.xls, append  ctitle("") keep(triple_1_w_only interact1 dum_w_only dum2_1_w_only) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons
*************************
**Rice only
gen r_only = (w==0 & r==1)

gen triple_1_r_only = interact1*r_only


gen dum_r_only = r_only*post_dif


gen dum2_1_r_only = r_only*marketing_reform


areg log_real_agwage triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only marketing_reform i.yr_qtr [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using riceo_statedddfeb.xls, replace  ctitle("") keep(triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only ) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

areg log_real_agwage triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only marketing_reform i.yr_qtr $indiv_controls $dist_controls [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using riceo_statedddfeb.xls, append  ctitle("") keep(triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only ) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons


areg log_real_agwage triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only marketing_reform i.yr_qtr nsstate_* $indiv_controls $dist_controls [aweight=weight], cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using riceo_statedddfeb.xls, append  ctitle("") keep(triple_1_r_only interact1 dum_r_only dum2_1_r_only r_only ) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons

*** Robustness

egen ste = group(state)

forval x = 1/18{

areg log_real_agwage triple_1_r interact1 dum dum2_1 r marketing_reform i.yr_qtr nssdist_* $indiv_controls $dist_controls [aweight=weight] if(ste!=`x'), cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using rice_robust.xls, append  ctitle("Excluding" `x') keep(triple_1_r) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons


areg log_real_agwage triple_1_w interact1 dum_w dum2_1_w w marketing_reform i.yr_qtr nssdist_* $indiv_controls $dist_controls[aweight=weight] if(ste!=`x'), cluster(new_state_dist_code) absorb(new_state_dist_code)
outreg2 using wheat_robust.xls, append  ctitle("Excluding" `x') keep(triple_1_w) addtext(State FE, YES, Year FE, YES, Demographic Controls, NO, Agriculture Controls, YES, State Specific Linear Time Trend, NO) nocons
}

*********************************************


